<?php

/**
 * 框架核心类
 */
class Framework
{
    
    public $ModlueName;
    public $ControllerName;
    public $ActionName;
    
    //运行程序
    public function run(){
    
        $this->route();
        $this->load();
    }
    
    // 路由处理
    public function route(){
        $dynamic = explode('/',trim($_SERVER['REQUEST_URI'],'/')); //动态路径
        
        // halt($dynamic);
        define('MODLUE',empty($dynamic[0]) ? 'api':$dynamic[0]);
        define('CONTROLLER',empty(ucfirst($dynamic[1])) ? 'Index':ucfirst($dynamic[1]));
        define('ACTION',empty($dynamic[2]) ? 'index':$dynamic[2]);
        
        include 'Helper.php';
        include 'Controller.php';
        include MODLUE.'/'.CONTROLLER.'.php';
    }
    
    //自动加载控制器和模型类 
    public function load(){
        $Package = MODLUE.'\\'.CONTROLLER;
        
        $action = ACTION;
        $Object = new $Package();
        $Object->$action();
    }
}

$Framework = new Framework();